const fsPromise = require('fs/promises')
const fs = require('fs')
const {exec} = require("child_process");
const { shell, app} = require('electron')
const path = require("path");

function _getHardSerial(){
    return new Promise((resolve, reject) => {
        let command = '';
        switch (process.platform) {
            case 'win32':
                command = 'wmic diskdrive get SerialNumber';
                break;
            case 'linux':
                command = 'lsblk -d -n -o serial';
                break;
            case 'darwin':
                reject(new Error('未知'));
                break;
            default:
                reject(new Error(`Unsupported platform: ${process.platform}`));
        }
        exec(command, (err, stdout, stderr) => {
            if (err) {
                reject(err);
            } else {
                resolve(stdout.trim());
            }
        });
    });
}

exports.getCpu=()=>{

    return _getHardSerial().then((serialNumber) => {
        var str = serialNumber.split("\r\r\n");

        return  str[1];
    }).catch((err) => {
        console.error(`Failed to get CPU serial number: ${err.message}`);
        return err.message;
    })
}
// exports.getPluginPath=()=>{
//     let pluginPath = ''
//     if (app.isPackaged) {
//         pluginPath = path.join(process.env.electronResources, 'plugin/')
//     } else {
//         console.log(process.env.devRoot)
//         pluginPath = path.join(process.env.devRoot, 'public/plugin/')
//     }
//     return pluginPath
// }
